<?php

// Created by Khanh Nam
class RequireLoginFilter extends CFilter {

    public function preFilter($filterChain) {
       
        if (Yii::app()->user->isGuest && Yii::app()->controller->route != 'site/login') {
            Yii::app()->controller->redirect(Yii::app()->controller->createUrl('site/login'));
        }
        switch (Yii::app()->user->usertype) {
            case Useraccess::Type_Sales_Team :
                if (empty(Yii::app()->controller->module->id) || Yii::app()->controller->module->id != 'salespersonportal')
                    Yii::app()->controller->redirect(Yii::app()->controller->createUrl('/salespersonportal'));

                break;
            case Useraccess::Type_Employee :
                if (empty(Yii::app()->controller->module->id) || Yii::app()->controller->module->id != 'employeeportal')
                    Yii::app()->controller->redirect(Yii::app()->controller->createUrl('/employeeportal'));
                break;
            case Useraccess::Type_Customer:
                if (empty(Yii::app()->controller->module->id) || Yii::app()->controller->module->id != 'customerportal')
                    Yii::app()->controller->redirect(Yii::app()->controller->createUrl('customerportal'));

                break;
            case Useraccess::Type_Admin :
    
                break;


            default:
                break;
        }   
       

        /*
          if (!empty(Yii::app()->user->custno) && Yii::app()->controller->route != 'site/logout'){

          if (empty(Yii::app()->controller->module->id)|| Yii::app()->controller->module->id!= 'customerportal')
          Yii::app()->controller->redirect(Yii::app()->controller->createUrl('/customerportal'));
          }

          if (!empty(Yii::app()->user->empno) && Yii::app()->controller->route != 'site/logout'){

          if (empty(Yii::app()->controller->module->id)|| Yii::app()->controller->module->id!= 'salespersonportal')
          Yii::app()->controller->redirect(Yii::app()->controller->createUrl('/salespersonportal'));
          }

          } */
        $filterChain->run();
    }

}

?>
